-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid moving inside SpiDmaBus
, abort dropped transfers
#2216
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rip, I had a PR brewing around this stuff. (Maybe we should start coordinating work around this).
What's wrong with the moving? It shouldn't get in the way of implementing zerocopy transfers?
I only ask because I'll have to do some re-designing if it's the only way forward.
It's impossible to piece together the peripheral's state if the user drops the transaction, especially in async. |
Wasn't the |
This comment was marked as outdated.
This comment was marked as outdated.
Btw how did you know setting the datalen to zero would get the SPI to stop? Trial and error? Or was this a hidden nugget of info in |
Completely by accident. As far as I can see, esp-idf has no concept of aborting a queued (or other in-progress) transfer. The questions around the async API will be discussed during today's Rust Embedded meeting: rust-embedded/wg#796 (comment) |
3ec8d4a
to
72a9c23
Compare
4e6d8f5
to
d375aad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would it take to convince you to keep the moving in SpiDmaBus
? 😄
Just did a quick code size test and there is a 13K difference in my app (for ESP32-S3) between this branch and the branch's base. I'll happily take a 0.9% code size difference from just the SPI driver.
I'm not opposed to creating short-lived buffer types that may end up getting moved (and I'm even taking a step in that direction in a later PR), but I'd rather not move the peripheral itself internally, and I think the current state demonstrates that at least that part isn't necessary. |
It never was. Having said all that, you can disregard that comment/request from me. Adding the new dma buffer view stuff to SPI has been a challenge (due to the full duplex nature of the peripheral), I probably won't be touching the SPI driver until all the other drivers use the dma buffers. |
This PR doesn't change that public API, but allows us some more flexibility in our impl, whilst also solving cancellation safety (something that I guess is going to be a problem using the move API in down stream crates, but I don't think we need to worry about that just yet).
I do tend to agree with your principle in general, but I don't think we're using unsafe for the sake of it, we're doing it for a reason. Tbh if |
f437287
to
2d47c7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
This PR simplifies SPI implementation by not relying on the move API internally. The PR also implements stopping transfers when their corresponding handle is dropped. This is probbaly better in line with embedded-hal expectations, and this change is necessary to enable zero-copy implementations of the embedded-hal traits (where applicable, of course. We still need to copy if the source data can't be accessed by the DMA).
Testing
Added and ran HIL tests, observed SPI waveforms using a logic analyzer on ESP32 and ESP32-C6.